﻿package mortal.game.scene3D.map3D.AstarAnyDirection.data
{
    import flash.geom.*;

    public class AstarIILink extends Object
    {
        public var otherNode:AstarIIPoint;
        public var minCol:Number;
        public var minRow:Number;
        public var maxCol:Number;
        public var maxRow:Number;
        public var isJumpLink:Boolean = false;

        public function AstarIILink()
        {
            return;
        }// end function

        public function setCommon(param1:Number, param2:Number, param3:Number, param4:Number) : void
        {
            if (param4 <= param2)
            {
                var _loc_5:* = Math.max(param1, param3);
                this.minCol = Math.max(param1, param3);
                this.minRow = _loc_5;
                var _loc_5:* = param4;
                this.maxCol = param4;
                this.maxRow = _loc_5;
            }
            else if (param3 <= param2)
            {
                var _loc_5:* = Math.max(param1, param3);
                this.minCol = Math.max(param1, param3);
                this.minRow = _loc_5;
                var _loc_5:* = param2;
                this.maxCol = param2;
                this.maxRow = _loc_5;
            }
            return;
        }// end function

        public function getLinksDistance(param1:AstarIILink) : Number
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:Number = NaN;
            _loc_2 = this.minCol - param1.minCol;
            _loc_3 = this.minRow - param1.minRow;
            _loc_4 = _loc_2 * _loc_2 + _loc_3 * _loc_3;
            _loc_2 = this.minCol - param1.maxCol;
            _loc_3 = this.minRow - param1.maxRow;
            _loc_4 = Math.min(_loc_4, _loc_2 * _loc_2 + _loc_3 * _loc_3);
            _loc_2 = this.maxCol - param1.minCol;
            _loc_3 = this.maxRow - param1.minRow;
            _loc_4 = Math.min(_loc_4, _loc_2 * _loc_2 + _loc_3 * _loc_3);
            _loc_2 = this.maxCol - param1.maxCol;
            _loc_3 = this.maxRow - param1.maxRow;
            _loc_4 = _loc_4 + Math.min(_loc_4, _loc_2 * _loc_2 + _loc_3 * _loc_3);
            return Math.sqrt(_loc_4 / 2);
        }// end function

        public function calcDistance(param1:Point, param2:Point, param3:Point, param4:Point, param5:Point) : Number
        {
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            param3.x = this.minCol;
            param3.y = this.minRow;
            param4.x = this.maxCol;
            param4.y = this.maxRow;
            if (GeomUtil.calcSegmentsCrossPoint(param1, param2, param3, param4, param5, false))
            {
                return GeomUtil.calcDistance(param1.x, param1.y, param5.x, param5.y);
            }
            var _loc_6:* = GeomUtil.calcDistance(param1.x, param1.y, param3.x, param3.y);
            var _loc_7:* = GeomUtil.calcDistance(param1.x, param1.y, param4.x, param4.y);
            var _loc_8:* = _loc_6 + GeomUtil.calcDistance(param3.x, param3.y, param2.x, param2.y);
            var _loc_9:* = _loc_7 + GeomUtil.calcDistance(param4.x, param4.y, param2.x, param2.y);
            if (_loc_8 < _loc_9)
            {
                param5.x = param3.x;
                param5.y = param3.y;
                return _loc_6;
            }
            param5.x = param4.x;
            param5.y = param4.y;
            return _loc_7;
        }// end function

    }
}
